home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / d3_fonts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  4.5 KB  |  196 lines

  1. /*****************************************************************************
  2.   FILE           : d3_fonts.c
  3.   SHORTNAME      : fonts.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : font selection and character drawing
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Ralf Huebner
  10.   DATE           : 1.12.1991
  11.  
  12.   CHANGED BY     : Sven Doering
  13.   IDENTIFICATION : @(#)d3_fonts.c    1.12 3/2/94
  14.   SCCS VERSION   : 1.12
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdio.h>
  21. #include <X11/Xlib.h>
  22. #include <X11/Intrinsic.h>
  23.  
  24. #include "glob_typ.h"
  25. #include "d3_global.h"
  26. #include "d3_fonts.ph"
  27. #include "d3_point.h"
  28. #include "d3_zgraph.h"
  29. #include "d3_graph.h"
  30.  
  31. #include "d3_font5x7.h"
  32. #include "d3_font5x8.h"
  33. #include "d3_font8x14.h"
  34.  
  35.  
  36. /*****************************************************************************
  37.   FUNCTION : d3_select_font
  38.  
  39.   PURPOSE  : select a font
  40.   RETURNS  : 
  41.   NOTES    : set width and height of the font
  42.  
  43. ******************************************************************************/
  44.  
  45.  
  46. void d3_select_font (int selected_font)
  47. {
  48.     switch (selected_font) {
  49.        case fnt5x7:  font = font5x7; 
  50.                      width = font5x7_width;
  51.                      height = font5x7_height;
  52.                      break;
  53.        case fnt5x8:  font = font5x8; 
  54.                      width = font5x8_width;
  55.                      height = font5x8_height;
  56.                      break;
  57.        default:      font = font8x14; 
  58.                      width = font8x14_width;
  59.                      height = font8x14_height;
  60.                      break;
  61.     }
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69. /*****************************************************************************
  70.   FUNCTION : d3_get_font_size
  71.  
  72.   PURPOSE  : gets the width and height of the current font
  73.   RETURNS  : width and height
  74.   NOTES    :
  75.  
  76. ******************************************************************************/
  77.  
  78.  
  79. void d3_get_font_size (int *x, int *y)
  80. {
  81.     *x = width;
  82.     *y = height;
  83. }
  84.  
  85.  
  86.  
  87. /*****************************************************************************
  88.   FUNCTION : draw_char
  89.  
  90.   PURPOSE  : draws the charcter c at (xpos, ypos)
  91.   RETURNS  : 
  92.   NOTES    :
  93.  
  94. ******************************************************************************/
  95.  
  96.  
  97. static void draw_char (int xpos, int ypos, unsigned char ch)
  98. {
  99.      int xsize, ysize, index, dx, dy;
  100.      unsigned char b;
  101.  
  102.  
  103.      xsize = width - 1;
  104.      ysize = height - 1;
  105.      index = height * ch;
  106.  
  107.      for (dy=0; dy<=ysize; dy++) {
  108.          b = font[index];
  109.          for (dx=0; dx<=xsize; dx++) {
  110.              if ((b >> (7-dx)) & 0x01)
  111.                  d3_putPixel (xpos+dx, ypos+dy);
  112.          }
  113.          index++;
  114.      }
  115. }
  116.  
  117.  
  118.  
  119. /*****************************************************************************
  120.   FUNCTION : draw_zbuffered_char
  121.  
  122.   PURPOSE  : draws the z-bufferd charcter c at (xpos, ypos, zpos)
  123.   RETURNS  : 
  124.   NOTES    :
  125.  
  126. ******************************************************************************/
  127.  
  128.  
  129.  
  130. static void draw_zbuffered_char (int xpos, int ypos, float zpos, unsigned char ch)
  131. {
  132.      int xsize, ysize, index, dx, dy, xp, yp;
  133.      float zp;
  134.      unsigned char b;
  135.  
  136.  
  137.      xsize = width - 1;
  138.      ysize = height - 1;
  139.      index = height * ch;
  140.  
  141.      for (dy=0; dy<=ysize; dy++) {
  142.          b = font[index];
  143.          for (dx=0; dx<=xsize; dx++) {
  144.              if ((b >> (7-dx)) & 0x01) {
  145.                  xp = xpos + dx;
  146.                  yp = ypos + dy;
  147.                  if ((xp >= d3_clipWindow.x0) && (yp >= d3_clipWindow.y0) 
  148.                      && (yp < d3_clipWindow.y1) && (xp < d3_clipWindow.x1)) {
  149.                      d3_readZbuffer (xp, yp, &zp);
  150.                      if (zpos < zp) {
  151.                          d3_putPixel(xp, yp);
  152.                          d3_writeZbuffer (xp, yp, zpos);
  153.              }
  154.                  }
  155.          }
  156.          }
  157.          index++;
  158.      }
  159. }
  160.  
  161.  
  162.  
  163. /*****************************************************************************
  164.   FUNCTION : d3_draw_string
  165.  
  166.   PURPOSE  : draws a string
  167.   RETURNS  : 
  168.   NOTES    : check wether z buffering is active
  169.  
  170. ******************************************************************************/
  171.  
  172.  
  173.  
  174. void d3_draw_string (int xpos, int ypos, float zpos, char *s)
  175. {
  176.     d3_setBlackColor ();
  177.     if (d3_state.model_mode == solid)
  178.         for (; *s!='\0'; s++) {
  179.            draw_zbuffered_char (xpos, ypos, zpos, *s);
  180.            xpos += width + 1;
  181.     }
  182.     else
  183.         for (; *s!='\0'; s++) {
  184.            draw_char (xpos, ypos, *s);
  185.            xpos += width + 1;
  186.     }
  187.     
  188. }
  189.  
  190.  
  191.  
  192. /* end of file */
  193. /* lines: 212 */
  194.  
  195.  
  196.